const ci = require('NODE_PATH/miniprogram-ci')
async function uploadCode() {
    const projectConfig = projectInfo({
        type: 'miniProgram',
        ignores: ['node_modules/**/*'],
        appid: 'MP_APPID',
        projectPath: './dist/build/mp-weixin/',
        privateKeyPath: './certificate/private.MP_APPID.key'
    })
    // 预览
    await previewWeiXinCode(projectConfig);
    // 上传
    return await uploadWeiXinCode(projectConfig);
}
//创建待上传项目的项目信息
const projectInfo = project => {
    return new ci.Project(project)
}
const uploadWeiXinCode = async function (project) {
    const uploadResult = await ci.upload({
        project,
        version: "MP_VERSION",
        desc: "MP_DESC",
        setting: {
            urlCheck: true,
            es6: true,
            es7: true,
            postcss: true,
            minified: true
        },
        threads: 2,
        useCOS: true,
        onProgressUpdate: console.log('previewing: ')
    })
}
const previewWeiXinCode = async function (project) {
    const previewResult = await ci.preview({
        project,
        desc: '上传代码',
        setting: {
            urlCheck: true,
            es6: true,
            es7: true,
            postcss: true,
            minified: true
        },
        qrcodeFormat: 'image',
        qrcodeOutputDest: 'QRCODE_PATH',
        onProgressUpdate: console.log('uploading: ')
    })
}

; (async () => {
    try {
        await uploadCode();
        process.exit(0);
    } catch (error) {
        console.log("update wechart of error", error);
        process.exit(1);
    }
})();
